feat(forge): notify router + snapshot apply (RIG-2732) - #676
Merged
Conversation
… ack frame (RIG-2732)
Piece-2 T3: the wire + store slice for forge agent-notification.
## Proto (additive, one regen; buf-breaking-safe)
- `agent_gateway.proto`: new `ForgeSubscriptionScope` enum (UNSPECIFIED=0 / ARTIFACT=1 / CONTAINER=2) and two additive `SubscribeForgeRequest` fields `scope=4`, `project=5` (fields 1-3 untouched).
- `forge.proto`: two additive `ForgeNotificationKind` values `REVIEW=5`, `OPENED=6`.
- `agent.proto`: one additive `AgentFrame` oneof variant `forge_notification_ack=8` (next free field after `transcript_entry=7`) + the `ForgeNotificationAck { subscription_id, revision }` message, the forge sibling of `DeliveryAck`.
- Regenerated Go (`go/internal/gen/`) and the agent TS client via `moon run compass-proto:gen`.
## DDL (`0001_init.sql`, edited in place — greenfield single migration)
- `agent_forge_subscriptions` gains `scope SMALLINT NOT NULL DEFAULT 1 CHECK (scope IN (1,2))` and `project TEXT NOT NULL DEFAULT ''`.
- UNIQUE widened to (agent_account_id, forge_provider, forge_host, repo, kind, number, project) so two Linear project containers on one team don't collide.
- `forge_artifact_cursors` unchanged (admits number=0 container rows; needs no project column).
## Store (`forge_subscriptions.go`)
- `ForgeSubscriptionScope` type + `normalizeScope` (UNSPECIFIED -> ARTIFACT; store never persists 0).
- `validSubscriptionCoordinate` learns scope: ARTIFACT => number>0 AND project empty; CONTAINER => number==0, project REQUIRED on LINEAR / FORBIDDEN elsewhere. Zero provider/kind/empty repo stay ErrInvalidArgument on every arm.
- `EnsureAgentForgeSubscription` persists scope+project on the widened UNIQUE.
- New surface: `SubscribersForArtifact` (exact + opened-event container fan-out, one indexed query), `ListForgeNotifyTargets` (LEFT JOIN cursors, container collapse per repo,kind), `UpsertForgeArtifactCursor`, `AdvanceForgeDeliveredRevision` (id+agent-scoped; zero rows -> ErrNotFound).
## Invariant
proto scope enum <-> SQL scope CHECK+UNIQUE <-> Go guard agree on ARTIFACT vs CONTAINER semantics: number is meaningful only under ARTIFACT; CONTAINER rows carry number=0 behind the explicit scope discriminator, with project distinguishing Linear projects.
## Tests
Red-green pgtests: container idempotency, scope-shape rejection (5 arms), Linear project-container distinctness, artifact fan-out (opened on/off, Linear project match/mismatch), targets grouping + container collapse + nil-cursor-before-upsert, advance happy/unknown/foreign-agent. Verified green on real Postgres.
Refs RIG-2732
Co-authored-by: Matt Wilkinson <matt@rigel.build>
This was referenced Aug 27, 2026
Merged
|
Compass engineering docs preview: https://compass-forge-rig-2732-t4-ro.compass-eng-docs.pages.dev Deployed from |
…r (RIG-2732) Review fixes for the wire+store slice (PR #674): - Reconcile the file-header + `ForgeArtifactCursor` struct doc: they claimed this file "never inserts a cursor row" and "the poll driver owns the cursor WRITER", but this slice added `UpsertForgeArtifactCursor` (the shared FETCH-cursor writer) and `ListForgeNotifyTargets` (the notify-target reader). The docs now name those. - Cover the container-scope cursor-attach branch: `TestListForgeNotifyTargetsContainerCollapse` now upserts a cursor at the container coordinate (number=0), re-lists, and asserts the collapsed container target carries it — exercising the `c.number=0` arm of the LEFT JOIN CASE that was untested. - Close test gaps: `validSubscriptionCoordinate` unknown-scope default arm; `AdvanceForgeDeliveredRevision` empty-agent / empty-subscription-id guards; a mixed artifact+container `ListForgeNotifyTargets` case pinning the collapse-vs-distinct boundary. Refs RIG-2732 Co-authored-by: Matt Wilkinson <matt@rigel.build>
T2 of RIG-2732 Piece-2 (webhook-only agent-notification): the event front door for both providers, producing the pipeline's single normalized currency (`forge.ForgeEvent`). - `internal/forge/notify_event.go`: the `ForgeEvent` normalized-currency struct. - `internal/forge/githubapp_webhook.go`: `VerifyGitHubSignature` (constant-time HMAC-SHA256 over the raw body) + `ParseGitHubEvent` mapping the Approach event table to normalized events; bodies stripped via `StripOwner` at normalize (the one strip point); `check_suite.completed` carries `HeadSHA` with a nil `ChecksSummary` (router fetches the roll-up). - `internal/linearagent/data_event.go`: `ParseLinearDataEvent` for Issue/Comment data-change payloads (create->OPENED, update->STATE-iff-updatedFrom-state else UPDATE, comment->COMMENT; remove counted-and-dropped; project id -> `ForgeEvent.Project`). - `server/github_webhook.go`: `NewGitHubWebhookHandler` — the DL-254 shape (verify -> ack 200 -> enqueue), delivery-id LRU dedup, oversized-body rejection. Unmounted (T7 wires it). Red-first unit tests cover signature vectors, every event-table row, PR-vs-issue comment discrimination, Linear state-vs-update, project id mapping, `check_suite` HeadSHA+nil-Checks, `StripOwner`, and the handler's signature/oversize/dedup paths. Refs RIG-2732 Co-authored-by: Matt Wilkinson <matt@rigel.build>
…G-2732) Review fixes for the webhook ingress slice (PR #675), all reconciling code to the frozen design record (design.md:534-537): - Body cap 25 MiB -> 1 MiB (design.md:536): keeps the per-request buffered-body allocation small (events are single-digit KB); the old 25 MiB opened a 25x-wider memory-amplification window than the record authorizes. - Enforce ack-fast: document that `ForgeEventSink.Enqueue` MUST NOT block (it hands off to the async drain loop), and flush the 200 onto the wire before Enqueue so a blocking sink can never delay the client-visible ack. - Bad/missing signature returns 400, not 401 (design.md:535). - Add handler tests: verified-but-malformed -> 200 + no enqueue; missing signature header -> 400; secret-unavailable -> 503. Add event-table rows for issues `reopened` -> STATE and pull_request `unlabeled` -> UPDATE. Refs RIG-2732 Co-authored-by: Matt Wilkinson <matt@rigel.build>
T4: the `ForgeEvent` hot path — `NotifyRouter.Route` + pure `ApplyEvent`/`SnapshotRevision`. - `notify_router.go`: package-local structural seams (`NotifyStore`, `NotifyDispatcher`, `ChecksRoller`) + `NotifyRouter`. `Route` runs the frozen algorithm (design.md:841-872): load prior snapshot -> resolve CHECKS roll-up before apply -> `ApplyEvent` -> upsert cursor BEFORE notify -> resolve subs (OPENED=container/project-matched, per-artifact=exact coordinate) -> dispatch a `ForgeNotification` carrying revision. Never advances `delivered_revision` (W3, ack-driven). - `notify_detect.go`: `ArtifactSnapshot` canonical form + pure `ApplyEvent` + `SnapshotRevision` (sha256 of canonical JSON, sorted checks, map-keyed comments) — the cross-producer meeting-point contract shared with T5. - Red-first unit tests with fakes for both seams, incl. the meeting-point invariant. Reconciled seams (single-admissible readings, not open forks): `NotifyStore` gained `LoadArtifactCursor` (the frozen 3-method block omits the point read the algorithm's step 1 needs); `ChecksRoller` returns a placeholder `ChecksResult` in this commit, collapsed into the real `forge.ConditionalResult[forge.Checks]` by T5 stacked above; UPDATE/REVIEW are snapshot-neutral and labels are excluded from the digest (the `ForgeEvent` currency carries no title/body/labels, so the canonicalization invariant holds trivially). Refs RIG-2732 Co-authored-by: Matt Wilkinson <matt@rigel.build>
…-2732) Review fixes for the notify router slice (PR #676): - Extend `Route`'s coordinate guard to reject `ev.Number == 0`, not just zero provider/kind. The frozen Global Constraint makes a zero number a caller bug for every event kind (ForgeEvent.Number is always set; on OPENED it is the new artifact's number), so a zero-number event must be `ErrInvalidArgument`, never a bogus number-0 cursor write. OPENED is unaffected (it carries the new artifact's number). - Add router error-path tests: a `LoadArtifactCursor` error aborts before upsert/dispatch; a `ChecksRoller` error on a CHECKS event aborts before apply; an `UpsertArtifactCursor` error surfaces and dispatches nothing (proving upsert-before-notify ordering under failure). These fakes exposed the error fields but no test set them. Refs RIG-2732 Co-authored-by: Matt Wilkinson <matt@rigel.build>
rigel-mintaka
force-pushed
the
compass-forge/rig-2732-t2-ingress
branch
from
August 27, 2026 08:51
e8f7a9f to
4e56465
Compare
rigel-mintaka
force-pushed
the
compass-forge/rig-2732-t4-router
branch
from
August 27, 2026 08:52
0732b93 to
5ac4f40
Compare
rigel-mintaka
marked this pull request as ready for review
August 27, 2026 09:05
mattwilkinsonn
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is part of a stack containing 4 PRs:
mainT4: the
ForgeEventhot path —NotifyRouter.Route+ pureApplyEvent/SnapshotRevision.notify_router.go: package-local structural seams (NotifyStore,NotifyDispatcher,ChecksRoller) +NotifyRouter.Routeruns the frozen algorithm (design.md:841-872): load prior snapshot -> resolve CHECKS roll-up before apply ->ApplyEvent-> upsert cursor BEFORE notify -> resolve subs (OPENED=container/project-matched, per-artifact=exact coordinate) -> dispatch aForgeNotificationcarrying revision. Never advancesdelivered_revision(W3, ack-driven).notify_detect.go:ArtifactSnapshotcanonical form + pureApplyEvent+SnapshotRevision(sha256 of canonical JSON, sorted checks, map-keyed comments) — the cross-producer meeting-point contract shared with T5.Reconciled seams (single-admissible readings, not open forks):
NotifyStoregainedLoadArtifactCursor(the frozen 3-method block omits the point read the algorithm's step 1 needs);ChecksRollerreturns a placeholderChecksResultin this commit, collapsed into the realforge.ConditionalResult[forge.Checks]by T5 stacked above; UPDATE/REVIEW are snapshot-neutral and labels are excluded from the digest (theForgeEventcurrency carries no title/body/labels, so the canonicalization invariant holds trivially).Refs RIG-2732
Co-authored-by: Matt Wilkinson matt@rigel.build